package com.imy.luascript.app.ui.demo;

import android.content.res.AssetManager;
import android.view.View;
import android.widget.ListView;

import com.imy.common.base.adapter.BaseSimpleListAdapter;
import com.imy.luascript.R;
import com.imy.luascript.app.ui.code.CodeActivity;
import com.imy.luascript.base.activity.BaseViewActivity;
import com.imy.luascript.viewmodel.BaseViewModel;

import java.io.IOException;
import java.util.Arrays;

import butterknife.BindView;

public class DemoActivity extends BaseViewActivity {

  @BindView(R.id.list_view) ListView mListView;

  private DemoListAdapter mAdapter;

  @Override
  protected BaseViewModel getViewModel() {
    return null;
  }



  @Override
  protected void initView() {
    setToolbarTitle(R.string.demo);
    try {
      AssetManager assets = getResources().getAssets();
      String[] list = assets.list("demo");
      DemoListAdapter adapter = new DemoListAdapter(this, Arrays.asList(list));
      adapter.setOnItemClickListener(new BaseSimpleListAdapter.onItemClickListener<String>() {
        @Override
        public void onItemClick(String bean, View itemView, int position) {
          String path = "demo/" + bean ;
          CodeActivity.start(self, path, bean);

        }
      });
      mListView.setAdapter(adapter);

    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  @Override
  protected int getLayoutID() {
    return R.layout.activity_demo;
  }

}
